home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / termReviewBuffer.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  35KB  |  1,797 lines

  1. /*
  2. **    termReviewBuffer.c
  3. **
  4. **    Support routines for the review buffer
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Menu item codes. */
  13.  
  14. enum    {    MEN_SEARCH,MEN_REPEAT,MEN_CLEARBUF,MEN_QUITBUF };
  15.  
  16.     /* Gadget ID codes. */
  17.  
  18. enum    {    GAD_SCROLLER, GAD_UP, GAD_DOWN };
  19.  
  20.     /* The arrow image height. */
  21.  
  22. #define ARROW_HEIGHT    11
  23.  
  24. STATIC struct NewMenu ReviewMenu[] =
  25. {
  26.     { NM_TITLE, NULL,         0 , 0, 0, (APTR)0},
  27.     {  NM_ITEM, NULL,         0 , 0, 0, (APTR)MEN_SEARCH},
  28.     {  NM_ITEM, NULL,         0 , 0, 0, (APTR)MEN_REPEAT},
  29.     {  NM_ITEM, NM_BARLABEL,     0 , 0, 0, (APTR)0},
  30.     {  NM_ITEM, NULL,         0 , 0, 0, (APTR)MEN_CLEARBUF},
  31.     {  NM_ITEM, NM_BARLABEL,     0 , 0, 0, (APTR)0},
  32.     {  NM_ITEM, NULL,         0 , 0, 0, (APTR)MEN_QUITBUF},
  33.  
  34.     { NM_END, 0,             0 , 0, 0, (APTR)0}
  35. };
  36.  
  37.     /* Local routines. */
  38.  
  39. STATIC VOID        ReviewUpdatePot(VOID);
  40. STATIC VOID __stdargs    ReviewWrites(STRPTR String,...);
  41. STATIC VOID __regargs    PrintReviewLine(STRPTR Buffer,LONG Line);
  42. STATIC VOID __regargs    RefreshReview(LONG Top);
  43. STATIC VOID __regargs    ScrollReview(LONG Top);
  44. STATIC BYTE        ReviewQuery(VOID);
  45. STATIC UBYTE __regargs    GetReviewChar(BYTE WaitForIt);
  46.  
  47.     /* Local variables. */
  48.  
  49. STATIC struct Menu        *ReviewMenuStrip;
  50.  
  51. STATIC struct IBox         ReviewBox;
  52. STATIC struct IOStdReq        *ReviewWriteRequest,
  53.                 *ReviewReadRequest;
  54.  
  55. STATIC struct MsgPort        *ReviewWritePort;
  56.  
  57. STATIC struct Gadget        *Scroller,
  58.                 *UpArrow,
  59.                 *DownArrow;
  60.  
  61. STATIC UWORD             RightBorderWidth;
  62.  
  63. STATIC struct Image        *UpImage,
  64.                 *DownImage;
  65.  
  66. STATIC UBYTE             ReviewChar;
  67. STATIC LONG             ReviewColumns,ReviewLines,
  68.                  ReviewTop = -1,ReviewGlobalLines;
  69.  
  70. STATIC struct SearchInfo    *ReviewSearchInfo;
  71. STATIC BYTE             SearchForward = TRUE;
  72.  
  73. STATIC UBYTE            *ReviewLineWidths;
  74. STATIC LONG             ReviewMaxLines;
  75.  
  76.     /* SplitEventReport():
  77.      *
  78.      *    Split a raw console input event report into components.
  79.      */
  80.  
  81. STATIC VOID __regargs
  82. SplitEventReport(STRPTR Buffer,LONG Len,UBYTE *Class,UWORD *Code,UWORD *Qualifier,ULONG *Prev)
  83. {
  84.     STRPTR    Start = Buffer;
  85.     LONG    Count = 0;
  86.  
  87.     if(Prev)
  88.         *Prev = NULL;
  89.  
  90.     while(Len--)
  91.     {
  92.         if(*Buffer == ';')
  93.         {
  94.             *Buffer++ = 0;
  95.  
  96.             switch(Count++)
  97.             {
  98.                 case 0:    *Class = Atol(Start);
  99.                     break;
  100.  
  101.                 case 2:    if(Code)
  102.                         *Code = Atol(Start);
  103.  
  104.                     break;
  105.  
  106.                 case 3:    if(Qualifier)
  107.                         *Qualifier = Atol(Start);
  108.  
  109.                     break;
  110.  
  111.                 case 4:    if(Prev)
  112.                         *Prev = Atol(Start) << 16;
  113.  
  114.                     break;
  115.  
  116.                 case 5:    if(Prev)
  117.                         *Prev |= Atol(Start);
  118.  
  119.                     break;
  120.             }
  121.  
  122.             Start = Buffer;
  123.         }
  124.         else
  125.             Buffer++;
  126.     }
  127. }
  128.  
  129.     /* ReviewDeleteScroller(VOID):
  130.      *
  131.      *    Delete scroller and arrow buttons.
  132.      */
  133.  
  134. STATIC VOID
  135. ReviewDeleteScroller(VOID)
  136. {
  137.     if(Scroller)
  138.     {
  139.         DisposeObject(Scroller);
  140.  
  141.         Scroller = NULL;
  142.     }
  143.  
  144.     if(UpArrow)
  145.     {
  146.         DisposeObject(UpArrow);
  147.  
  148.         UpArrow = NULL;
  149.     }
  150.  
  151.     if(DownArrow)
  152.     {
  153.         DisposeObject(DownArrow);
  154.  
  155.         DownArrow = NULL;
  156.     }
  157.  
  158.     if(UpImage)
  159.     {
  160.         DisposeObject(UpImage);
  161.  
  162.         UpImage = NULL;
  163.     }
  164.  
  165.     if(DownImage)
  166.     {
  167.         DisposeObject(DownImage);
  168.  
  169.         DownImage = NULL;
  170.     }
  171. }
  172.  
  173.     /* ReviewCreateScroller(struct Screen *Screen):
  174.      *
  175.      *    Create scroller and arrow buttons.
  176.      */
  177.  
  178. STATIC BYTE __regargs
  179. ReviewCreateScroller(struct Screen *Screen)
  180. {
  181.     struct DrawInfo    *DrawInfo;
  182.     BYTE         Result = FALSE;
  183.  
  184.     if(DrawInfo = GetScreenDrawInfo(Screen))
  185.     {
  186.         LONG    SizeWidth,
  187.             SizeHeight;
  188.         UWORD    SizeType;
  189.  
  190.         if(Screen -> Flags & SCREENHIRES)
  191.         {
  192.             SizeWidth    = 18;
  193.             SizeHeight    = 10;
  194.  
  195.             SizeType    = SYSISIZE_MEDRES;
  196.         }
  197.         else
  198.         {
  199.             SizeWidth    = 13;
  200.             SizeHeight    = 11;
  201.  
  202.             SizeType    = SYSISIZE_LOWRES;
  203.         }
  204.  
  205.         RightBorderWidth = SizeWidth;
  206.  
  207.         if(UpImage = (struct Image *)NewObject(NULL,"sysiclass",
  208.             SYSIA_Size,    SizeType,
  209.             SYSIA_Which,    UPIMAGE,
  210.             SYSIA_DrawInfo,    DrawInfo,
  211.         TAG_DONE))
  212.         {
  213.             if(DownImage = (struct Image *)NewObject(NULL,"sysiclass",
  214.                 SYSIA_Size,    SizeType,
  215.                 SYSIA_Which,    DOWNIMAGE,
  216.                 SYSIA_DrawInfo,    DrawInfo,
  217.             TAG_DONE))
  218.             {
  219.                 if(Scroller = NewObject(NULL,"propgclass",
  220.                     GA_ID,        GAD_SCROLLER,
  221.  
  222.                     GA_Top,        Screen -> WBorTop + Screen -> Font -> ta_YSize + 2,
  223.                     GA_RelHeight,    -(Screen -> WBorTop + Screen -> Font -> ta_YSize + 2 + SizeHeight + 1 + 2 * ARROW_HEIGHT),
  224.                     GA_Width,    SizeWidth - 8,
  225.                     GA_RelRight,    -(SizeWidth - 5),
  226.  
  227.                     GA_Immediate,    TRUE,
  228.                     GA_FollowMouse,    TRUE,
  229.                     GA_RelVerify,    TRUE,
  230.                     GA_RightBorder,    TRUE,
  231.  
  232.                     PGA_Freedom,    FREEVERT,
  233.                     PGA_NewLook,    TRUE,
  234.                     PGA_Borderless,    TRUE,
  235.  
  236.                     PGA_Visible,    1,
  237.                     PGA_Total,    1,
  238.                 TAG_DONE))
  239.                 {
  240.                     STATIC struct TagItem ArrowMappings[] =
  241.                     {
  242.                         GA_ID,    GA_ID,
  243.                         TAG_END
  244.                     };
  245.  
  246.                     if(UpArrow = NewObject(NULL,"buttongclass",
  247.                         GA_ID,        GAD_UP,
  248.  
  249.                         GA_Image,    UpImage,
  250.                         GA_RelRight,    -(SizeWidth - 1),
  251.                         GA_RelBottom,    -(SizeHeight - 1 + 2 * ARROW_HEIGHT),
  252.                         GA_Height,    ARROW_HEIGHT,
  253.                         GA_Width,    SizeWidth,
  254.                         GA_Immediate,    TRUE,
  255.                         GA_RelVerify,    TRUE,
  256.                         GA_Previous,    Scroller,
  257.                         GA_RightBorder,    TRUE,
  258.  
  259.                         ICA_TARGET,    ICTARGET_IDCMP,
  260.                         ICA_MAP,    ArrowMappings,
  261.                     TAG_DONE))
  262.                     {
  263.                         if(DownArrow = NewObject(NULL,"buttongclass",
  264.                             GA_ID,        GAD_DOWN,
  265.  
  266.                             GA_Image,    DownImage,
  267.                             GA_RelRight,    -(SizeWidth - 1),
  268.                             GA_RelBottom,    -(SizeHeight - 1 + ARROW_HEIGHT),
  269.                             GA_Height,    ARROW_HEIGHT,
  270.                             GA_Width,    SizeWidth,
  271.                             GA_Immediate,    TRUE,
  272.                             GA_RelVerify,    TRUE,
  273.                             GA_Previous,    UpArrow,
  274.                             GA_RightBorder,    TRUE,
  275.  
  276.                             ICA_TARGET,    ICTARGET_IDCMP,
  277.                             ICA_MAP,    ArrowMappings,
  278.                         TAG_DONE))
  279.                             Result = TRUE;
  280.                     }
  281.                 }
  282.             }
  283.         }
  284.  
  285.         FreeScreenDrawInfo(Screen,DrawInfo);
  286.     }
  287.  
  288.     return(Result);
  289. }
  290.  
  291.     /* ReviewUpdatePot():
  292.      *
  293.      *    Update size and position of the scroller gadget.
  294.      */
  295.  
  296. STATIC VOID
  297. ReviewUpdatePot()
  298. {
  299.     if(ReviewGlobalLines)
  300.     {
  301.         SetGadgetAttrs(Scroller,ReviewWindow,NULL,
  302.             PGA_Top,    ReviewTop,
  303.             PGA_Visible,    ReviewLines,
  304.             PGA_Total,    ReviewGlobalLines,
  305.         TAG_DONE);
  306.     }
  307. }
  308.  
  309.     /* ReviewUp(LONG Count):
  310.      *
  311.      *    Move the contents of the review buffer up.
  312.      */
  313.  
  314. STATIC VOID __regargs
  315. ReviewUp(LONG Count)
  316. {
  317.     if(BufferLines)
  318.     {
  319.         if(Count == 1)
  320.         {
  321.             if(ReviewTop)
  322.             {
  323.                 WORD i;
  324.  
  325.                 for(i = ReviewMaxLines - 2 ; i >= 0 ; i--)
  326.                     ReviewLineWidths[i + 1] = ReviewLineWidths[i];
  327.  
  328.                 ReviewTop--;
  329.  
  330.                 ReviewWrites("\33[T");
  331.  
  332.                 ObtainSemaphore(BufferSemaphore);
  333.  
  334.                 PrintReviewLine(BufferLines[ReviewTop],1);
  335.  
  336.                 ReviewUpdatePot();
  337.  
  338.                 ReleaseSemaphore(BufferSemaphore);
  339.             }
  340.         }
  341.         else
  342.         {
  343.             LONG NewTop = ReviewTop;
  344.  
  345.             if(NewTop >= Count)
  346.                 NewTop -= Count;
  347.             else
  348.                 NewTop = 0;
  349.  
  350.             if(NewTop != ReviewTop)
  351.             {
  352.                 ScrollReview(NewTop);
  353.  
  354.                 ReviewUpdatePot();
  355.             }
  356.         }
  357.     }
  358. }
  359.  
  360.     /* ReviewDown(LONG Count):
  361.      *
  362.      *    Move the contents of the review buffer down.
  363.      */
  364.  
  365. STATIC VOID __regargs
  366. ReviewDown(LONG Count)
  367. {
  368.     if(BufferLines)
  369.     {
  370.         if(Count == 1)
  371.         {
  372.             if(ReviewTop + ReviewLines < Lines)
  373.             {
  374.                 LONG Last;
  375.                 WORD i;
  376.  
  377.                 for(i = 0 ; i < ReviewMaxLines - 1 ; i++)
  378.                     ReviewLineWidths[i] = ReviewLineWidths[i + 1];
  379.  
  380.                 ReviewTop++;
  381.  
  382.                 ReviewWrites("\33[S");
  383.  
  384.                 ObtainSemaphore(BufferSemaphore);
  385.  
  386.                 if((Last = ReviewTop + ReviewLines) < Lines)
  387.                     PrintReviewLine(BufferLines[Last],ReviewLines + 1);
  388.  
  389.                 ReviewUpdatePot();
  390.  
  391.                 ReleaseSemaphore(BufferSemaphore);
  392.             }
  393.         }
  394.         else
  395.         {
  396.             LONG NewTop = ReviewTop;
  397.  
  398.             if((NewTop + Count + ReviewLines) > Lines)
  399.             {
  400.                 if((NewTop = Lines - ReviewLines) < 0)
  401.                     NewTop = 0;
  402.             }
  403.             else
  404.                 NewTop += Count;
  405.  
  406.             if(NewTop != ReviewTop)
  407.             {
  408.                 ScrollReview(NewTop);
  409.  
  410.                 ReviewUpdatePot();
  411.             }
  412.         }
  413.     }
  414. }
  415.  
  416.     /* ReviewWrites(STRPTR String,...):
  417.      *
  418.      *    Write a string into the review buffer window.
  419.      */
  420.  
  421. STATIC VOID __stdargs
  422. ReviewWrites(STRPTR String,...)
  423. {
  424.     va_list    VarArgs;
  425.  
  426.     va_start(VarArgs,String);
  427.     VSPrintf(SharedBuffer,String,VarArgs);
  428.     va_end(VarArgs);
  429.  
  430.     ReviewWriteRequest -> io_Command    = CMD_WRITE;
  431.     ReviewWriteRequest -> io_Data        = SharedBuffer;
  432.     ReviewWriteRequest -> io_Length        = -1;
  433.  
  434.     DoIO(ReviewWriteRequest);
  435. }
  436.  
  437.     /* FilterReviewLine(register STRPTR Line,register LONG Length):
  438.      *
  439.      *    Replace non-printable characters in the text line
  440.      *    to be printed.
  441.      */
  442.      
  443.  
  444. STATIC STRPTR __regargs
  445. FilterReviewLine(register STRPTR Line,register LONG Length)
  446. {
  447.     STATIC UBYTE ISO[256] =
  448.     {
  449.          46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
  450.          46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
  451.          32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  452.          48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  453.          64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  454.          80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  455.          96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
  456.         112,113,114,115,116,117,118,119,120,121,122,123,124,125,126, 46,
  457.          46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
  458.          46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
  459.         160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
  460.         176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
  461.         192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
  462.         208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
  463.         224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
  464.         240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
  465.     };
  466.  
  467.     STATIC UBYTE TempBuffer[256];
  468.  
  469.     register STRPTR Destination = TempBuffer;
  470.  
  471.     while(Length--)
  472.         *Destination++ = ISO[*Line++];
  473.  
  474.     return(TempBuffer);
  475. }
  476.  
  477.     /* PrintReviewLine(STRPTR Buffer,LONG Line):
  478.      *
  479.      *    Write the contents of a buffer line into the review buffer window.
  480.      */
  481.  
  482. STATIC VOID __regargs
  483. PrintReviewLine(STRPTR Buffer,LONG Line)
  484. {
  485.     WORD Length = Buffer[-1];
  486.  
  487.     if(Length > ReviewColumns)
  488.         Length = ReviewColumns;
  489.  
  490.     ReviewWrites("\33[%ldH",Line);
  491.  
  492.     ReviewWriteRequest -> io_Command    = CMD_WRITE;
  493.     ReviewWriteRequest -> io_Data        = FilterReviewLine(Buffer,Length);
  494.     ReviewWriteRequest -> io_Length        = Length;
  495.  
  496.     DoIO(ReviewWriteRequest);
  497.  
  498.     if(Length < ReviewLineWidths[Line - 1])
  499.         ReviewWrites("\33[0K");
  500.  
  501.     ReviewLineWidths[Line - 1] = Length;
  502. }
  503.  
  504.     /* RefreshReview(LONG Top):
  505.      *
  506.      *    Refresh the contents of the review buffer window.
  507.      */
  508.  
  509. STATIC VOID __regargs
  510. RefreshReview(LONG Top)
  511. {
  512.     LONG i,Last,Line = 0;
  513.  
  514.     ObtainSemaphore(BufferSemaphore);
  515.  
  516.     ReviewGlobalLines = Lines;
  517.  
  518.     if((Last = Top + ReviewLines + 1) >= Lines)
  519.     {
  520.         Last = Lines;
  521.  
  522.         if((Top = Last - ReviewLines) < 0)
  523.             Top = 0;
  524.  
  525.         ReviewTop = Top;
  526.     }
  527.  
  528.     if(BufferLines)
  529.     {
  530.         for(i = Top ; i < Last ; i++)
  531.             PrintReviewLine(BufferLines[i],++Line);
  532.     }
  533.  
  534.     if(Line <= ReviewLines)
  535.     {
  536.         if(Line)
  537.         {
  538.             for(i = Line - 1 ; i < ReviewLines ; i++)
  539.                 ReviewLineWidths[i] = 0;
  540.         }
  541.  
  542.         ReviewWrites("\33[0J\33[3%ldm",RenderPens[1] & 7);
  543.     }
  544.  
  545.     ReleaseSemaphore(BufferSemaphore);
  546. }
  547.  
  548.     /* MoveUp(VOID):
  549.      *
  550.      *    Move the review buffer contents up a line.
  551.      */
  552.  
  553. STATIC VOID
  554. MoveUp(VOID)
  555. {
  556.     LONG i;
  557.  
  558.     for(i = 0 ; i < ReviewMaxLines - 1 ; i++)
  559.         ReviewLineWidths[i] = ReviewLineWidths[i + 1];
  560.  
  561.     ReviewWrites("\33[S");
  562.  
  563.     ObtainSemaphore(BufferSemaphore);
  564.     PrintReviewLine(BufferLines[ReviewTop + ReviewLines],ReviewLines + 1);
  565.     ReleaseSemaphore(BufferSemaphore);
  566. }
  567.  
  568.     /* ScrollReview(LONG Top):
  569.      *
  570.      *    Refresh the contents of the review buffer window, reprint
  571.      *    as few lines as possible.
  572.      */
  573.  
  574. STATIC VOID __regargs
  575. ScrollReview(LONG Top)
  576. {
  577.     LONG i,Last,Line = 0,Delta,Total;
  578.  
  579.     ObtainSemaphore(BufferSemaphore);
  580.  
  581.     ReviewGlobalLines = Lines;
  582.  
  583.     Delta = Top - ReviewTop;
  584.  
  585.     ReviewTop = Top;
  586.  
  587.     if((Last = Top + ReviewLines + 1) >= Lines)
  588.         Last = Lines;
  589.  
  590.     Total = Last - Top;
  591.  
  592.     if(ABS(Delta) < ReviewLines)
  593.     {
  594.         if(!Delta)
  595.         {
  596.             ReleaseSemaphore(BufferSemaphore);
  597.  
  598.             return;
  599.         }
  600.         else
  601.         {
  602.             if(Delta < 0)
  603.             {
  604.                 Last = Top - Delta;
  605.  
  606.                 for(i = ReviewMaxLines - 1 ; i > -Delta ; i--)
  607.                     ReviewLineWidths[i] = ReviewLineWidths[i + Delta];
  608.  
  609.                 ReviewWrites("\33[%ldT",-Delta);
  610.             }
  611.             else
  612.             {
  613.                 for(i = Delta ; i < ReviewMaxLines ; i++)
  614.                     ReviewLineWidths[i - Delta] = ReviewLineWidths[i];
  615.  
  616.                 Top += ReviewLines - Delta;
  617.                 Line = ReviewLines - Delta;
  618.  
  619.                 ReviewWrites("\33[%ldS",Delta);
  620.             }
  621.         }
  622.     }
  623.  
  624.     if(BufferLines)
  625.     {
  626.         for(i = Top ; i < Last ; i++)
  627.             PrintReviewLine(BufferLines[i],++Line);
  628.     }
  629.  
  630.     if(Total <= ReviewLines)
  631.         ReviewWrites("\33[0J");
  632.  
  633.     ReleaseSemaphore(BufferSemaphore);
  634. }
  635.  
  636.     /* ReviewQuery():
  637.      *
  638.      *    Update the current review buffer window dimensions.
  639.      */
  640.  
  641. STATIC BYTE
  642. ReviewQuery()
  643. {
  644.     struct ConUnit    *Unit = (struct ConUnit *)ReviewWriteRequest -> io_Unit;
  645.     BYTE         Refresh = FALSE;
  646.  
  647.     memset(ReviewLineWidths,0,ReviewMaxLines);
  648.  
  649.     if(ReviewColumns != Unit -> cu_XMax)
  650.     {
  651.         Refresh = TRUE;
  652.  
  653.         ReviewColumns = Unit -> cu_XMax;
  654.     }
  655.  
  656.     if(ReviewLines != Unit -> cu_YMax)
  657.     {
  658.         if(ReviewTop + ReviewLines == Lines)
  659.         {
  660.             LONG Delta = ReviewLines - Unit -> cu_YMax;
  661.  
  662.             if(Delta < 0)
  663.                 ReviewTop += Delta;
  664.             else
  665.                 ReviewTop -= Delta;
  666.  
  667.             if(ReviewTop < 0)
  668.                 ReviewTop = 0;
  669.         }
  670.  
  671.         Refresh = TRUE;
  672.  
  673.         ReviewLines = Unit -> cu_YMax;
  674.     }
  675.  
  676.     if(Refresh)
  677.         ReviewUpdatePot();
  678.  
  679.     return(TRUE);
  680. }
  681.  
  682.     /* GetReviewChar(BYTE WaitForIt):
  683.      *
  684.      *    Get the next character present at the console read port.
  685.      */
  686.  
  687. STATIC UBYTE __regargs
  688. GetReviewChar(BYTE WaitForIt)
  689. {
  690.     UBYTE Char;
  691.  
  692.     if(!WaitForIt)
  693.     {
  694.         if(!CheckIO(ReviewReadRequest))
  695.             return(0);
  696.     }
  697.  
  698.     WaitIO(ReviewReadRequest);
  699.  
  700.     Char = ReviewChar;
  701.  
  702.     ReviewReadRequest -> io_Command    = CMD_READ;
  703.     ReviewReadRequest -> io_Data    = &ReviewChar;
  704.     ReviewReadRequest -> io_Length    = 1;
  705.  
  706.     SendIO(ReviewReadRequest);
  707.  
  708.     return(Char);
  709. }
  710.  
  711.     /* MarkReviewLine(STRPTR Buffer,LONG Line,LONG Column,LONG Len):
  712.      *
  713.      *    Similar to PrintReviewLine(), but also allows to mark a
  714.      *    certain word on the line.
  715.      */
  716.  
  717. STATIC VOID __regargs
  718. MarkReviewLine(STRPTR Buffer,LONG Line,LONG Column,LONG Len)
  719. {
  720.     WORD Length = Buffer[-1];
  721.  
  722.     if(Length > ReviewColumns)
  723.         Length = ReviewColumns;
  724.  
  725.     ReviewWrites("\33[%ldH",Line);
  726.  
  727.     if(Length <= Column)
  728.     {
  729.         ReviewWriteRequest -> io_Command    = CMD_WRITE;
  730.         ReviewWriteRequest -> io_Data        = Buffer;
  731.         ReviewWriteRequest -> io_Length        = Length;
  732.  
  733.         DoIO(ReviewWriteRequest);
  734.  
  735.         ReviewWrites("\33[0K");
  736.     }
  737.     else
  738.     {
  739.         ReviewWriteRequest -> io_Command    = CMD_WRITE;
  740.         ReviewWriteRequest -> io_Data        = Buffer;
  741.         ReviewWriteRequest -> io_Length        = Column;
  742.  
  743.         DoIO(ReviewWriteRequest);
  744.  
  745.         ReviewWrites("\33[7;3%ldm",RenderPens[1] & 7);
  746.  
  747.         ReviewWriteRequest -> io_Command    = CMD_WRITE;
  748.         ReviewWriteRequest -> io_Data        = &Buffer[Column];
  749.         ReviewWriteRequest -> io_Length        = Len;
  750.  
  751.         DoIO(ReviewWriteRequest);
  752.  
  753.         ReviewWrites("\33[0;3%ldm",RenderPens[1] & 7);
  754.  
  755.         if(Column + Len < Length)
  756.         {
  757.             ReviewWriteRequest -> io_Command    = CMD_WRITE;
  758.             ReviewWriteRequest -> io_Data        = &Buffer[Column + Len];
  759.             ReviewWriteRequest -> io_Length        = Length - (Column + Len);
  760.  
  761.             DoIO(ReviewWriteRequest);
  762.         }
  763.  
  764.         ReviewWrites("\33[0K");
  765.     }
  766. }
  767.  
  768.     /* ReviewMarkArea(LONG Top,LONG Column,LONG Line,LONG Len,BYTE FullRefresh):
  769.      *
  770.      *    Mark a word on the current display.
  771.      */
  772.  
  773. STATIC VOID __regargs
  774. ReviewMarkArea(LONG Top,LONG Column,LONG Line,LONG Len,BYTE FullRefresh)
  775. {
  776.     STATIC LONG LastMarked = -1;
  777.  
  778.     LONG i,Last,LineIndex = 0;
  779.  
  780.     ReviewGlobalLines = Lines;
  781.  
  782.     ObtainSemaphore(BufferSemaphore);
  783.  
  784.     if((Last = Top + ReviewLines + 1) >= Lines)
  785.         Last = Lines;
  786.  
  787.     if(FullRefresh)
  788.     {
  789.         if(BufferLines)
  790.         {
  791.             for(i = Top ; i < Last ; i++)
  792.             {
  793.                 if(i != Line)
  794.                     PrintReviewLine(BufferLines[i],++LineIndex);
  795.                 else
  796.                     MarkReviewLine(BufferLines[i],++LineIndex,Column,Len);
  797.             }
  798.         }
  799.  
  800.         if(LineIndex <= ReviewLines)
  801.             ReviewWrites("\33[0J");
  802.     }
  803.     else
  804.     {
  805.         if(BufferLines)
  806.         {
  807.             for(i = Top ; i < Last ; i++)
  808.             {
  809.                 LineIndex++;
  810.  
  811.                 if(i == LastMarked)
  812.                     PrintReviewLine(BufferLines[i],LineIndex);
  813.  
  814.                 if(i == Line)
  815.                     MarkReviewLine(BufferLines[i],LineIndex,Column,Len);
  816.             }
  817.         }
  818.     }
  819.  
  820.     LastMarked = Line;
  821.  
  822.     ReleaseSemaphore(BufferSemaphore);
  823. }
  824.  
  825.     /* ReviewSearch(BYTE Repeat):
  826.      *
  827.      *    Search for a certain word in the text buffer.
  828.      */
  829.  
  830. STATIC VOID
  831. ReviewSearch(BYTE Repeat)
  832. {
  833.     if(Lines)
  834.     {
  835.         STATIC UBYTE SearchBuffer[256];
  836.  
  837.         LONG LineNumber;
  838.  
  839.         if(!Repeat || !SearchBuffer[0])
  840.         {
  841.             if(GetSearchString(ReviewWindow,NULL,SearchBuffer,&SearchForward))
  842.             {
  843.                 if(SearchBuffer[0])
  844.                 {
  845.                     if(ReviewSearchInfo)
  846.                         DeleteSearchInfo(ReviewSearchInfo);
  847.  
  848.                     ReviewSearchInfo = CreateSearchInfo(SearchBuffer,SearchForward);
  849.                 }
  850.                 else
  851.                     return;
  852.             }
  853.             else
  854.                 return;
  855.         }
  856.         else
  857.         {
  858.             if(!ReviewSearchInfo)
  859.                 ReviewSearchInfo = CreateSearchInfo(SearchBuffer,TRUE);
  860.         }
  861.  
  862.         if(ReviewSearchInfo)
  863.         {
  864.             ObtainSemaphore(BufferSemaphore);
  865.  
  866.             LineNumber = SearchTextBuffer(ReviewSearchInfo);
  867.  
  868.             ReleaseSemaphore(BufferSemaphore);
  869.  
  870.             if(LineNumber == -1)
  871.             {
  872.                 RefreshReview(ReviewTop);
  873.  
  874.                 MyEasyRequest(ReviewWindow,LocaleString(MSG_TERMBUFFER_DID_NOT_FIND_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SearchBuffer);
  875.  
  876.                 ReviewSearchInfo -> FoundY = -1;
  877.             }
  878.             else
  879.             {
  880.                 if(LineNumber < ReviewTop || LineNumber > ReviewTop + ReviewLines)
  881.                 {
  882.                     if(LineNumber + ReviewLines > Lines)
  883.                     {
  884.                         ReviewTop = Lines - ReviewLines;
  885.  
  886.                         if(ReviewTop < 0)
  887.                             ReviewTop = 0;
  888.                     }
  889.                     else
  890.                         ReviewTop = LineNumber;
  891.  
  892.                     ReviewUpdatePot();
  893.  
  894.                     ReviewMarkArea(ReviewTop,ReviewSearchInfo -> FoundX,LineNumber,ReviewSearchInfo -> PatternWidth,TRUE);
  895.                 }
  896.                 else
  897.                     ReviewMarkArea(ReviewTop,ReviewSearchInfo -> FoundX,LineNumber,ReviewSearchInfo -> PatternWidth,FALSE);
  898.             }
  899.         }
  900.     }
  901.     else
  902.         MyEasyRequest(ReviewWindow,LocaleString(MSG_GLOBAL_NOTHING_IN_THE_BUFFER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  903. }
  904.  
  905.     /* DeleteReview():
  906.      *
  907.      *    Delete the review buffer.
  908.      */
  909.  
  910. VOID
  911. DeleteReview()
  912. {
  913.     CheckItem(MEN_REVIEW_WINDOW,FALSE);
  914.  
  915.     if(ReviewReadRequest)
  916.     {
  917.         if(ReviewReadRequest -> io_Device)
  918.         {
  919.             if(!CheckIO(ReviewReadRequest))
  920.                 AbortIO(ReviewReadRequest);
  921.  
  922.             WaitIO(ReviewReadRequest);
  923.         }
  924.  
  925.         FreeVec(ReviewReadRequest);
  926.  
  927.         ReviewReadRequest = NULL;
  928.     }
  929.  
  930.     if(ReviewWriteRequest)
  931.     {
  932.         if(ReviewWriteRequest -> io_Device)
  933.             CloseDevice(ReviewWriteRequest);
  934.  
  935.         DeleteIORequest(ReviewWriteRequest);
  936.  
  937.         ReviewWriteRequest = NULL;
  938.     }
  939.  
  940.     if(ReviewWindow)
  941.     {
  942.         PutWindowInfo(WINDOW_REVIEW,ReviewWindow -> LeftEdge,ReviewWindow -> TopEdge,ReviewWindow -> Width,ReviewWindow -> Height);
  943.  
  944.         ClearMenuStrip(ReviewWindow);
  945.  
  946.         CloseWindow(ReviewWindow);
  947.  
  948.         ReviewWindow = NULL;
  949.     }
  950.  
  951.     if(ReviewMenuStrip)
  952.     {
  953.         FreeMenus(ReviewMenuStrip);
  954.  
  955.         ReviewMenuStrip = NULL;
  956.     }
  957.  
  958.     ReviewDeleteScroller();
  959.  
  960.     if(ReviewWritePort)
  961.     {
  962.         DeleteMsgPort(ReviewWritePort);
  963.  
  964.         ReviewWritePort = NULL;
  965.     }
  966.  
  967.     if(ReviewPort)
  968.     {
  969.         DeleteMsgPort(ReviewPort);
  970.  
  971.         ReviewPort = NULL;
  972.     }
  973.  
  974.     if(ReviewSearchInfo)
  975.     {
  976.         DeleteSearchInfo(ReviewSearchInfo);
  977.  
  978.         ReviewSearchInfo = NULL;
  979.     }
  980.  
  981.     if(ReviewLineWidths)
  982.     {
  983.         FreeVec(ReviewLineWidths);
  984.  
  985.         ReviewLineWidths = NULL;
  986.     }
  987. }
  988.  
  989.     /* CreateReview():
  990.      *
  991.      *    Create the review buffer.
  992.      */
  993.  
  994. BYTE
  995. CreateReview()
  996. {
  997.     if(ReviewBox . Left == -1)
  998.     {
  999.         ReviewBox . Left    = 0;
  1000.         ReviewBox . Top        = Window -> WScreen -> BarHeight + 1;
  1001.         ReviewBox . Width    = Window -> WScreen -> Width;
  1002.         ReviewBox . Height    = Window -> WScreen -> Height - (Window -> WScreen -> BarHeight + 1);
  1003.     }
  1004.  
  1005.     if(ReviewCreateScroller(Window -> WScreen))
  1006.     {
  1007.         LocalizeMenu(ReviewMenu,MSG_TERMREVIEW_PROJECT_MEN);
  1008.  
  1009.         if(ReviewMenuStrip = CreateMenus(ReviewMenu,TAG_DONE))
  1010.         {
  1011.             if(LayoutMenus(ReviewMenuStrip,VisualInfo,
  1012.                 GTMN_TextAttr,        &UserFont,
  1013.                 GTMN_NewLookMenus,    TRUE,
  1014.             TAG_DONE))
  1015.             {
  1016.                 LONG    Left    = 0,
  1017.                     Top    = 0,
  1018.                     Width    = 0,
  1019.                     Height    = 0;
  1020.  
  1021.                 GetWindowInfo(WINDOW_REVIEW,&Left,&Top,&Width,&Height,NULL,Window -> WScreen -> WBorTop + Window -> WScreen -> WBorBottom + 1 + Window -> WScreen -> Font -> ta_YSize + 10 * CurrentFont -> tf_YSize);
  1022.  
  1023.                 if(ReviewWindow = OpenWindowTags(NULL,
  1024.                     WA_Left,        Left,
  1025.                     WA_Top,            Top,
  1026.                     WA_Width,        Width,
  1027.                     WA_Height,        Height,
  1028.                     WA_MinWidth,        Window -> WScreen -> WBorLeft + RightBorderWidth + 15 * CurrentFont -> tf_XSize,
  1029.                     WA_MinHeight,        Window -> WScreen -> WBorTop + Window -> WScreen -> WBorBottom + 1 + Window -> WScreen -> Font -> ta_YSize + 2 * CurrentFont -> tf_YSize,
  1030.                     WA_MaxWidth,        Window -> WScreen -> Width,
  1031.                     WA_MaxHeight,        Window -> WScreen -> Height,
  1032.                     WA_DragBar,        TRUE,
  1033.                     WA_CloseGadget,        TRUE,
  1034.                     WA_DepthGadget,        TRUE,
  1035.                     WA_SizeGadget,        TRUE,
  1036.                     WA_SizeBRight,        TRUE,
  1037.                     WA_IDCMP,        IDCMP_IDCMPUPDATE | IDCMP_GADGETDOWN | IDCMP_SIZEVERIFY | IDCMP_MOUSEMOVE | IDCMP_MENUPICK,
  1038.                     WA_Title,        LocaleString(MSG_TERMREVIEW_REVIEWBUFFER_TXT),
  1039.                     WA_CustomScreen,    Window -> WScreen,
  1040.                     WA_SimpleRefresh,    TRUE,
  1041.                     WA_RMBTrap,        TRUE,
  1042.                     WA_Activate,        TRUE,
  1043.                     WA_NewLookMenus,    TRUE,
  1044.                     WA_Zoom,        &ReviewBox,
  1045.                     WA_Gadgets,        Scroller,
  1046.                 TAG_DONE))
  1047.                 {
  1048.                     ReviewMaxLines = (ReviewWindow -> WScreen -> Height - (ReviewWindow -> BorderTop + ReviewWindow -> BorderBottom)) / CurrentFont -> tf_YSize;
  1049.  
  1050.                     if(ReviewLineWidths = (UBYTE *)AllocVec(ReviewMaxLines,MEMF_ANY | MEMF_CLEAR))
  1051.                     {
  1052.                         SetMenuStrip(ReviewWindow,ReviewMenuStrip);
  1053.  
  1054.                         SetFont(ReviewWindow -> RPort,CurrentFont);
  1055.  
  1056.                         if(ReviewWritePort = CreateMsgPort())
  1057.                         {
  1058.                             if(ReviewPort = CreateMsgPort())
  1059.                             {
  1060.                                 if(ReviewWriteRequest = CreateIORequest(ReviewPort,sizeof(struct IOStdReq)))
  1061.                                 {
  1062.                                     if(ReviewReadRequest = (struct IOStdReq *)AllocVec(sizeof(struct IOStdReq),MEMF_ANY | MEMF_CLEAR))
  1063.                                     {
  1064.                                         ReviewWriteRequest -> io_Data = ReviewWindow;
  1065.  
  1066.                                         if(!OpenDevice("console.device",CONU_SNIPMAP,ReviewWriteRequest,CONFLAG_NODRAW_ON_NEWSIZE))
  1067.                                         {
  1068.                                             CheckItem(MEN_REVIEW_WINDOW,TRUE);
  1069.  
  1070.                                             CopyMem(ReviewWriteRequest,ReviewReadRequest,sizeof(struct IOStdReq));
  1071.  
  1072.                                             ReviewReadRequest -> io_Message . mn_ReplyPort = ReviewPort;
  1073.  
  1074.                                             ReviewWrites("\33[0 p\33[1;11;12{\33[3%ldm",RenderPens[1] & 7);
  1075.  
  1076.                                             ReviewQuery();
  1077.  
  1078.                                             ObtainSemaphore(BufferSemaphore);
  1079.  
  1080.                                             if(ReviewTop == -1 || !Config -> CaptureConfig -> RememberBufferWindow)
  1081.                                             {
  1082.                                                 switch(Config -> CaptureConfig -> OpenBufferWindow)
  1083.                                                 {
  1084.                                                     case BUFFER_TOP:
  1085.  
  1086.                                                         ReviewTop = 0;
  1087.                                                         break;
  1088.  
  1089.                                                     case BUFFER_END:
  1090.  
  1091.                                                         if((ReviewTop = Lines - ReviewLines) < 0)
  1092.                                                             ReviewTop = 0;
  1093.  
  1094.                                                         break;
  1095.  
  1096.                                                     default:
  1097.  
  1098.                                                         ReviewTop = 0;
  1099.                                                         break;
  1100.                                                 }
  1101.                                             }
  1102.  
  1103.                                             if(ReviewTop > Lines - ReviewLines)
  1104.                                             {
  1105.                                                 if((ReviewTop = Lines - ReviewLines) < 0)
  1106.                                                     ReviewTop = 0;
  1107.                                             }
  1108.  
  1109.                                             ReleaseSemaphore(BufferSemaphore);
  1110.  
  1111.                                             RefreshReview(ReviewTop);
  1112.  
  1113.                                             ReviewUpdatePot();
  1114.  
  1115.                                             ReviewReadRequest -> io_Command    = CMD_READ;
  1116.                                             ReviewReadRequest -> io_Data    = &ReviewChar;
  1117.                                             ReviewReadRequest -> io_Length    = 1;
  1118.  
  1119.                                             SendIO(ReviewReadRequest);
  1120.  
  1121.                                             ReviewWindow -> Flags &= ~WFLG_RMBTRAP;
  1122.  
  1123.                                             return(TRUE);
  1124.                                         }
  1125.                                     }
  1126.                                 }
  1127.                             }
  1128.                         }
  1129.                     }
  1130.                 }
  1131.             }
  1132.         }
  1133.     }
  1134.  
  1135.     DeleteReview();
  1136.  
  1137.     return(FALSE);
  1138. }
  1139.  
  1140.     /* UpdateReview():
  1141.      *
  1142.      *    Update the contents of the review buffer window.
  1143.      */
  1144.  
  1145. VOID
  1146. UpdateReview(BYTE Force)
  1147. {
  1148.     if(ReviewPort)
  1149.     {
  1150.         if(Force)
  1151.         {
  1152.             if(Lines)
  1153.             {
  1154.                 if(ReviewTop > 0)
  1155.                 {
  1156.                     SetGadgetAttrs(Scroller,ReviewWindow,NULL,
  1157.                         PGA_Top,--ReviewTop,
  1158.                     TAG_DONE);
  1159.                 }
  1160.                 else
  1161.                     MoveUp();
  1162.             }
  1163.         }
  1164.         else
  1165.         {
  1166.             if(Lines >= ReviewGlobalLines && ReviewGlobalLines <= ReviewLines)
  1167.                 RefreshReview(ReviewTop);
  1168.         }
  1169.  
  1170.         ReviewGlobalLines = Lines;
  1171.  
  1172.         if(!Lines)
  1173.         {
  1174.             SetGadgetAttrs(Scroller,ReviewWindow,NULL,
  1175.                 PGA_Top,    ReviewTop = 0,
  1176.                 PGA_Visible,    1,
  1177.                 PGA_Total,    1,
  1178.             TAG_DONE);
  1179.  
  1180.             ReviewWrites("\f\33[3%ldm",RenderPens[1] & 7);
  1181.         }
  1182.         else
  1183.             ReviewUpdatePot();
  1184.     }
  1185. }
  1186.  
  1187.     /* MoveReview(BYTE Mode):
  1188.      *
  1189.      *    Move the currently visible review area.
  1190.      */
  1191.  
  1192. VOID
  1193. MoveReview(BYTE Mode)
  1194. {
  1195.     LONG NewTop;
  1196.  
  1197.     switch(Mode)
  1198.     {
  1199.         case REVIEW_MOVE_TOP:
  1200.  
  1201.             if(ReviewTop)
  1202.             {
  1203.                 ScrollReview(0);
  1204.  
  1205.                 ReviewUpdatePot();
  1206.             }
  1207.  
  1208.             break;
  1209.  
  1210.         case REVIEW_MOVE_BOTTOM:
  1211.  
  1212.             NewTop = Lines - ReviewLines;
  1213.  
  1214.             if(NewTop < 0)
  1215.                 NewTop = 0;
  1216.  
  1217.             if(ReviewTop != NewTop)
  1218.             {
  1219.                 ScrollReview(NewTop);
  1220.  
  1221.                 ReviewUpdatePot();
  1222.             }
  1223.  
  1224.             break;
  1225.  
  1226.         case REVIEW_MOVE_UP:
  1227.  
  1228.             ReviewUp(ReviewLines);
  1229.             break;
  1230.  
  1231.         case REVIEW_MOVE_DOWN:
  1232.  
  1233.             ReviewDown(ReviewLines);
  1234.             break;
  1235.     }
  1236. }
  1237.  
  1238.     /* HandleReview():
  1239.      *
  1240.      *    Process console and user input.
  1241.      */
  1242.  
  1243. BYTE
  1244. HandleReview()
  1245. {
  1246.     UBYTE    IClass;
  1247.     UWORD    ICode,
  1248.         IQualifier;
  1249.     BYTE    Result = FALSE;
  1250.  
  1251.     if(ReviewWindow)
  1252.     {
  1253.         struct IntuiMessage    *Message;
  1254.         struct MenuItem        *MenuItem;
  1255.         struct TagItem        *TagList;
  1256.         ULONG             IClass;
  1257.  
  1258.         if(Message = (struct IntuiMessage *)GetMsg(ReviewWindow -> UserPort))
  1259.         {
  1260.             IClass        = Message -> Class;
  1261.             ICode        = Message -> Code;
  1262.             IQualifier    = Message -> Qualifier;
  1263.             TagList        = (struct TagItem *)Message -> IAddress;
  1264.  
  1265.             ReplyMsg((struct Message *)Message);
  1266.  
  1267.             switch(IClass)
  1268.             {
  1269.                 case IDCMP_IDCMPUPDATE:
  1270.  
  1271.                     switch(GetTagData(GA_ID,0,TagList))
  1272.                     {
  1273.                         case GAD_UP:    ReviewUp(1);
  1274.                                 break;
  1275.  
  1276.                         case GAD_DOWN:    ReviewDown(1);
  1277.                                 break;
  1278.                     }
  1279.  
  1280.                     break;
  1281.  
  1282.                 case IDCMP_GADGETDOWN:
  1283.                 case IDCMP_MOUSEMOVE:
  1284.  
  1285.                     if(ReviewGlobalLines > ReviewLines)
  1286.                     {
  1287.                         LONG NewTop;
  1288.  
  1289.                         if(GetAttr(PGA_Top,Scroller,&NewTop))
  1290.                             ScrollReview(NewTop);
  1291.                     }
  1292.  
  1293.                     break;
  1294.  
  1295.                 case IDCMP_MENUPICK:
  1296.  
  1297.                     while(ICode != MENUNULL)
  1298.                     {
  1299.                         MenuItem = ItemAddress(ReviewMenuStrip,ICode);
  1300.  
  1301.                         switch((ULONG)GTMENUITEM_USERDATA(MenuItem))
  1302.                         {
  1303.                             case MEN_SEARCH:
  1304.  
  1305.                                 BlockWindow(ReviewWindow);
  1306.  
  1307.                                 ReviewSearch(FALSE);
  1308.  
  1309.                                 ReleaseWindow(ReviewWindow);
  1310.  
  1311.                                 break;
  1312.  
  1313.                             case MEN_REPEAT:
  1314.  
  1315.                                 BlockWindow(ReviewWindow);
  1316.  
  1317.                                 ReviewSearch(TRUE);
  1318.  
  1319.                                 ReleaseWindow(ReviewWindow);
  1320.  
  1321.                                 break;
  1322.  
  1323.                             case MEN_QUITBUF:
  1324.  
  1325.                                 DeleteReview();
  1326.                                 return(TRUE);
  1327.  
  1328.                             case MEN_CLEARBUF:
  1329.  
  1330.                                 if(Lines)
  1331.                                 {
  1332.                                     BlockWindows();
  1333.  
  1334.                                     BlockWindow(ReviewWindow);
  1335.  
  1336.                                     if(IQualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
  1337.                                     {
  1338.                                         FreeBuffer();
  1339.  
  1340.                                         ReleaseWindow(ReviewWindow);
  1341.  
  1342.                                         ReleaseWindows();
  1343.  
  1344.                                         return(TRUE);
  1345.                                     }
  1346.                                     else
  1347.                                     {
  1348.                                         if(MyEasyRequest(ReviewWindow,LocaleString(MSG_TERMBUFFER_BUFFER_STILL_HOLDS_LINES_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT),Lines))
  1349.                                         {
  1350.                                             FreeBuffer();
  1351.  
  1352.                                             ReleaseWindow(ReviewWindow);
  1353.  
  1354.                                             ReleaseWindows();
  1355.  
  1356.                                             return(TRUE);
  1357.                                         }
  1358.                                     }
  1359.  
  1360.                                     ReleaseWindow(ReviewWindow);
  1361.  
  1362.                                     ReleaseWindows();
  1363.                                 }
  1364.  
  1365.                                 break;
  1366.                         }
  1367.  
  1368.                         ICode = MenuItem -> NextSelect;
  1369.                     }
  1370.  
  1371.                     break;
  1372.             }
  1373.  
  1374.             Result = TRUE;
  1375.         }
  1376.     }
  1377.  
  1378.         /* Check for raw input events. */
  1379.  
  1380.     if(ReviewPort)
  1381.     {
  1382.         UBYTE Char;
  1383.  
  1384.             /* Control sequence available? */
  1385.  
  1386.         if((Char = GetReviewChar(FALSE)) == CSI)
  1387.         {
  1388.             LONG    Len;
  1389.             ULONG    Prev;
  1390.             UBYTE    InputBuffer[257];
  1391.             WORD    Count = 0;
  1392.  
  1393.                 /* Try to read the entire sequence. */
  1394.  
  1395.             while(Char = GetReviewChar(FALSE))
  1396.             {
  1397.                 SharedBuffer[Count++] = Char;
  1398.  
  1399.                 if(Char != ' ' && Char != ';' && (Char < '0' || Char > '9'))
  1400.                     break;
  1401.             }
  1402.  
  1403.                 /* Provide termination. */
  1404.  
  1405.             SharedBuffer[Count] = 0;
  1406.  
  1407.                 /* Raw event? */
  1408.  
  1409.             if(Char == '|')
  1410.                 SplitEventReport(SharedBuffer,Count,&IClass,&ICode,&IQualifier,&Prev);
  1411.             else
  1412.                 IClass = 0;
  1413.  
  1414.             if(!strcmp(SharedBuffer,"0 v"))
  1415.             {
  1416.                 if(!ClipInput)
  1417.                 {
  1418.                     if(!OpenClip(Config -> ClipConfig -> ClipboardUnit))
  1419.                         ClipInput = TRUE;
  1420.                     else
  1421.                         ClipInput = FALSE;
  1422.  
  1423.                     ClipXerox = FALSE;
  1424.                 }
  1425.  
  1426.                 if(ClipInput)
  1427.                 {
  1428.                         /* Is a send-delay enabled? */
  1429.  
  1430.                     if(Config -> ClipConfig -> CharDelay || Config -> ClipConfig -> LineDelay)
  1431.                     {
  1432.                         while((Len = GetClip(InputBuffer,256,FALSE)) > 0)
  1433.                         {
  1434.                             WORD i;
  1435.  
  1436.                                 /* Run down the buffer... */
  1437.  
  1438.                             for(i = 0 ; i < Len ; i++)
  1439.                             {
  1440.                                 SerWrite(&InputBuffer[i],1);
  1441.  
  1442.                                     /* What kind of delay
  1443.                                      * are we to provide?
  1444.                                      */
  1445.  
  1446.                                 if(InputBuffer[i] == '\r')
  1447.                                 {
  1448.                                     if(Config -> ClipConfig -> LineDelay)
  1449.                                         WaitTime(Config -> ClipConfig -> LineDelay / 100,(Config -> ClipConfig -> LineDelay % 100) * 10000);
  1450.                                 }
  1451.                                 else
  1452.                                 {
  1453.                                     if(Config -> ClipConfig -> CharDelay)
  1454.                                         WaitTime(Config -> ClipConfig -> CharDelay / 100,(Config -> ClipConfig -> CharDelay % 100) * 10000);
  1455.                                 }
  1456.                             }
  1457.                         }
  1458.                     }
  1459.                     else
  1460.                     {
  1461.                         while((Len = GetClip(InputBuffer,256,FALSE)) > 0)
  1462.                             SerWrite(InputBuffer,Len);
  1463.                     }
  1464.  
  1465.                     CloseClip();
  1466.  
  1467.                     ClipInput = ClipPrefix = FALSE;
  1468.                 }
  1469.             }
  1470.             else
  1471.             {
  1472.                     /* Check the event type. */
  1473.  
  1474.                 switch(IClass)
  1475.                 {
  1476.                     case 1:
  1477.  
  1478.                             /* Convert the event... */
  1479.  
  1480.                         Char = ConvertTheKey(InputBuffer,&Len,ICode,IQualifier,Prev);
  1481.  
  1482.                             /* Lather, rinse, process as usual. */
  1483.  
  1484.                         if(Len)
  1485.                         {
  1486.                             switch(CharType[Char])
  1487.                             {
  1488.                                 case CHAR_HELP:
  1489.  
  1490.                                     GuideDisplay(CONTEXT_TEXTBUFFER);
  1491.  
  1492.                                     Len = 0;
  1493.  
  1494.                                     break;
  1495.  
  1496.                                 case CHAR_CURSOR:
  1497.  
  1498.                                     if(ClipInput)
  1499.                                     {
  1500.                                         CloseClip();
  1501.  
  1502.                                         ClipInput = ClipXerox = ClipPrefix = FALSE;
  1503.                                     }
  1504.  
  1505.                                     if(Char == CUP || Char == CDN)
  1506.                                     {
  1507.                                             /* Find the approriate qualifier. */
  1508.  
  1509.                                         if(IQualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
  1510.                                         {
  1511.                                             if(Char == CUP)
  1512.                                                 ReviewUp(ReviewLines);
  1513.                                             else
  1514.                                                 ReviewDown(ReviewLines);
  1515.                                         }
  1516.                                         else
  1517.                                         {
  1518.                                             if(IQualifier & (IEQUALIFIER_CONTROL | IEQUALIFIER_LALT | IEQUALIFIER_RALT))
  1519.                                             {
  1520.                                                 if(Char == CUP)
  1521.                                                 {
  1522.                                                     if(ReviewTop)
  1523.                                                     {
  1524.                                                         ScrollReview(0);
  1525.  
  1526.                                                         ReviewUpdatePot();
  1527.                                                     }
  1528.                                                 }
  1529.                                                 else
  1530.                                                 {
  1531.                                                     LONG NewTop = Lines - ReviewLines;
  1532.  
  1533.                                                     if(NewTop < 0)
  1534.                                                         NewTop = 0;
  1535.  
  1536.                                                     if(NewTop != ReviewTop)
  1537.                                                     {
  1538.                                                         ScrollReview(NewTop);
  1539.  
  1540.                                                         ReviewUpdatePot();
  1541.                                                     }
  1542.                                                 }
  1543.                                             }
  1544.                                             else
  1545.                                             {
  1546.                                                 if(Char == CUP)
  1547.                                                     ReviewUp(1);
  1548.                                                 else
  1549.                                                     ReviewDown(1);
  1550.                                             }
  1551.                                         }
  1552.                                     }
  1553.  
  1554.                                     Len = 0;
  1555.  
  1556.                                     break;
  1557.  
  1558.                                     /* Any function key pressed? */
  1559.  
  1560.                                 case CHAR_FUNCTION:
  1561.  
  1562.                                     if(ClipInput)
  1563.                                     {
  1564.                                         CloseClip();
  1565.  
  1566.                                         ClipInput = ClipXerox = ClipPrefix = FALSE;
  1567.                                     }
  1568.  
  1569.                                     if(IQualifier & IEQUALIFIER_CONTROL)
  1570.                                         SerialCommand(MacroKeys -> Keys[3][Char - FN1]);
  1571.                                     else
  1572.                                     {
  1573.                                         if(IQualifier & (IEQUALIFIER_LALT | IEQUALIFIER_RALT))
  1574.                                             SerialCommand(MacroKeys -> Keys[2][Char - FN1]);
  1575.                                         else
  1576.                                         {
  1577.                                             if(IQualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
  1578.                                                 SerialCommand(MacroKeys -> Keys[1][Char - FN1]);
  1579.                                             else
  1580.                                                 SerialCommand(MacroKeys -> Keys[0][Char - FN1]);
  1581.                                         }
  1582.                                     }
  1583.  
  1584.                                     Len = 0;
  1585.  
  1586.                                     break;
  1587.  
  1588.                                     /* Anything else? */
  1589.  
  1590.                                 default:
  1591.  
  1592.                                     if(Len == 1 && (IQualifier & IEQUALIFIER_NUMERICPAD) && (Config -> EmulationConfig -> NumericMode == KEYMODE_APPLICATION))
  1593.                                     {
  1594.                                         STATIC STRPTR ApplicationTable[20][2] =
  1595.                                         {
  1596.                                             "0",    "\033Op",
  1597.                                             "1",    "\033Oq",
  1598.                                             "2",    "\033Or",
  1599.                                             "3",    "\033Os",
  1600.                                             "4",    "\033Ot",
  1601.                                             "5",    "\033Ou",
  1602.                                             "6",    "\033Ov",
  1603.                                             "7",    "\033Ow",
  1604.                                             "8",    "\033Ox",
  1605.                                             "9",    "\033Oy",
  1606.                                             "-",    "\033Om",
  1607.                                             "+",    "\033Ol",    /* This should really be a comma */
  1608.                                             ".",    "\033On",
  1609.  
  1610.                                             "[",    "\033OP",
  1611.                                             "{",    "\033OP",
  1612.                                             "]",    "\033OQ",
  1613.                                             "}",    "\033OQ",
  1614.                                             "/",    "\033OR",
  1615.                                             "*",    "\033OS",
  1616.  
  1617.                                             "\r",    "\033OM"
  1618.                                         };
  1619.  
  1620.                                         WORD i;
  1621.  
  1622.                                         for(i = 0 ; i < 20 ; i++)
  1623.                                         {
  1624.                                             if(Char == ApplicationTable[i][0][0])
  1625.                                             {
  1626.                                                 if(ClipInput)
  1627.                                                 {
  1628.                                                     CloseClip();
  1629.  
  1630.                                                     ClipInput = ClipXerox = ClipPrefix = FALSE;
  1631.                                                 }
  1632.  
  1633.                                                 SerWrite(ApplicationTable[i][1],strlen(ApplicationTable[i][1]));
  1634.  
  1635.                                                 Len = 0;
  1636.  
  1637.                                                 break;
  1638.                                             }
  1639.                                         }
  1640.                                     }
  1641.  
  1642.                                     break;
  1643.                             }
  1644.  
  1645.                                 /* Any characters to send? */
  1646.  
  1647.                             if(Len)
  1648.                             {
  1649.                                 STRPTR    Buffer = InputBuffer;
  1650.                                 UBYTE    Mask,
  1651.                                     c;
  1652.  
  1653.                                     /* Strip the high order bit? */
  1654.  
  1655.                                 if(Config -> SerialConfig -> StripBit8)
  1656.                                     Mask = 0x7F;
  1657.                                 else
  1658.                                     Mask = 0xFF;
  1659.  
  1660.                                 if(ClipInput)
  1661.                                 {
  1662.                                     CloseClip();
  1663.  
  1664.                                     ClipInput = ClipXerox = ClipPrefix = FALSE;
  1665.                                 }
  1666.  
  1667.                                 while(Len--)
  1668.                                 {
  1669.                                     switch(CharType[c = (*Buffer++) & Mask])
  1670.                                     {
  1671.                                         case CHAR_ENTER:
  1672.  
  1673.                                             if(Status == STATUS_HOLDING)
  1674.                                                 DoBeep();
  1675.                                             else
  1676.                                             {
  1677.                                                 switch(Config -> TerminalConfig -> SendLF)
  1678.                                                 {
  1679.                                                     case LF_ASLF:
  1680.  
  1681.                                                         SerWrite("\n",1);
  1682.                                                         break;
  1683.  
  1684.                                                     case LF_ASLFCR:
  1685.  
  1686.                                                         SerWrite("\n\r",2);
  1687.                                                         break;
  1688.                                                 }
  1689.                                             }
  1690.  
  1691.                                             break;
  1692.  
  1693.                                         case CHAR_RETURN:
  1694.  
  1695.                                             if(Status == STATUS_HOLDING)
  1696.                                                 DoBeep();
  1697.                                             else
  1698.                                             {
  1699.                                                 switch(Config -> TerminalConfig -> SendCR)
  1700.                                                 {
  1701.                                                     case CR_ASCR:
  1702.  
  1703.                                                         SerWrite("\r",1);
  1704.                                                         break;
  1705.  
  1706.                                                     case CR_ASCRLF:
  1707.  
  1708.                                                         SerWrite("\r\n",2);
  1709.                                                         break;
  1710.                                                 }
  1711.                                             }
  1712.  
  1713.                                             break;
  1714.  
  1715.                                             /* Stop in/output. */
  1716.  
  1717.                                         case CHAR_XON:
  1718.  
  1719.                                             if(Status == STATUS_HOLDING)
  1720.                                                 DoBeep();
  1721.                                             else
  1722.                                             {
  1723.                                                 if(Config -> SerialConfig -> xONxOFF)
  1724.                                                     Status = STATUS_HOLDING;
  1725.  
  1726.                                                 if(Config -> SerialConfig -> PassThrough)
  1727.                                                     SerWrite(&c,1);
  1728.                                             }
  1729.  
  1730.                                             break;
  1731.  
  1732.                                             /* Restart in/output. */
  1733.  
  1734.                                         case CHAR_XOFF:
  1735.  
  1736.                                             if(Status == STATUS_HOLDING)
  1737.                                                 Status = STATUS_READY;
  1738.  
  1739.                                             if(Config -> SerialConfig -> PassThrough)
  1740.                                                 SerWrite(&c,1);
  1741.  
  1742.                                             break;
  1743.  
  1744.                                             /* Any other character. */
  1745.  
  1746.                                         case CHAR_VANILLA:
  1747.  
  1748.                                             if(Status == STATUS_HOLDING)
  1749.                                                 DoBeep();
  1750.                                             else
  1751.                                             {
  1752.                                                 if(Config -> TerminalConfig -> FontMode == FONT_IBM)
  1753.                                                 {
  1754.                                                         /* Convert special
  1755.                                                          * Amiga characters into
  1756.                                                          * alien IBM dialect.
  1757.                                                          */
  1758.  
  1759.                                                     if(IBMConversion[c])
  1760.                                                         SerWrite(&IBMConversion[c],1);
  1761.                                                     else
  1762.                                                         SerWrite(&c,1);
  1763.                                                 }
  1764.                                                 else
  1765.                                                     SerWrite(&c,1);
  1766.                                             }
  1767.  
  1768.                                             break;
  1769.                                     }
  1770.                                 }
  1771.                             }
  1772.                         }
  1773.  
  1774.                         break;
  1775.  
  1776.                     case 11:
  1777.  
  1778.                         DeleteReview();
  1779.  
  1780.                         return(Result);
  1781.  
  1782.                     case 12:
  1783.  
  1784.                         if(ReviewQuery())
  1785.                             RefreshReview(ReviewTop);
  1786.  
  1787.                         break;
  1788.                 }
  1789.             }
  1790.  
  1791.             return(TRUE);
  1792.         }
  1793.     }
  1794.  
  1795.     return(Result);
  1796. }
  1797.